@isTest
private class TechnicalServicesAppFormHandlerTest {
    static testMethod void testMethod1() {


        User u2= new User( Alias = 'samLdc2', 
                         Email = 'ldc2@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户2', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = [select Id from Profile where Name like '%工程师%' limit 1].Id , 
                         Country = 'United States',
                         IsActive = true,
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123452',
                         CompanyName = 'Y-MKSY',
                         FederationIdentifier = '123452',
                         Username = 'Matldc2@test.com.maike',
                         ResponseCode__c = 'TTTT' );
             insert u2;
        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc;


        Dealer__c d = new Dealer__c(
            Only__c='Dealer__c'
        );
        insert d;


          //产品结构
        ProductStructure__c ps1=new ProductStructure__c();
        ps1.Name='仪器';
        ps1.Classify1__c='生化';
        ps1.Classify2__c='生化-设备';
        ps1.Classify3__c='仪器';
        insert ps1;
        Brand__c brand = new Brand__c(
            BrandShortName__c = '四川迈克'
        );
        insert brand;
          //产品
        Product__c p1=TestUtils.createProduct();
        p1.Name='仪器';
        p1.Category0__c = '仪器';
        p1.Model__c='Model1228';
        p1.ProductStructure__c=ps1.Id;
        p1.CRMBrand__c = brand.Id;
        p1.RecordTypeId =  Utils.getRecordTypeIdByDevNameAndObjName('NCProduct','Product__c');
        insert p1;



          InstallationApply__c ins = new InstallationApply__c();
        ins.InstallationType__c='新装机';
        //必填字段 chatter 通知工作流引用到的字段都为必填字段
        ins.Instrument__c = p1.Id;
        ins.NEWDealer__c = d.Id;
        ins.Hospital__c = acc.Id;
        ins.InstallEstiDate__c = Date.newInstance(2017, 12, 1);
        ins.InstallsNumber__c = 1;
        ins.EffectiveTime__c = System.now();
        insert ins;

        Case cas=new Case();
        cas.AccountId=acc.Id;
        cas.InstallationApply__c = ins.Id;
        insert cas;

        TechnicalServicesApplicationForm__c ta = new TechnicalServicesApplicationForm__c();
        ta.CustomerName__c = acc.Id;
        ta.Status__c = '草案中';
        ta.Type__c = '安装';	
        ta.ServiceType__c = '工程';
        ta.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerSupportApplication', 'TechnicalServicesApplicationForm__c');
        ta.InstrumentModel__c = p1.Id;
        ta.MaccuraEngineer__c = u2.Id;
        ta.Case__c = cas.Id;
        insert ta;

 
        System.debug('TechnicalServicesAppFormHandlerTest==> '+[select Id ,Case__c ,MaccuraEngineer__c from TechnicalServicesApplicationForm__c where Id =:ta.Id  ]);
       	ta.Status__c = '已批准';
       	update ta;



        System.debug('TechnicalServicesAppFormHandlerTest==> '+[select Id ,Case__c ,MaccuraEngineer__c from TechnicalServicesApplicationForm__c where Id =:ta.Id  ]);




        
    }
}